package com.ftqh.tutorial.security.oauth2.provider.client.enums;

/**
 * Created by Administrator on 2016/12/29.
 */
public enum RefreshTokenValidity {
    SEVEN_DAY(60 * 60 * 24 * 7, "7天"),
    THIRTY_DAY(60 * 60 * 24 * 30, "30天"),
    SIXTY_DAY(60 * 60 * 24 * 60, "60天"),
    NINETY_DAY(60 * 60 * 24 * 90, "90天");

    private final Integer seconds;
    private String text;

    private RefreshTokenValidity(Integer seconds,String text){
        this.seconds = seconds;
        this.text = text;
    }
    public String getText() {
        return text;
    }
    public Integer getSeconds() {
        return seconds;
    }

    public static RefreshTokenValidity fromSeconds(Integer seconds) {
        if ( seconds.equals(604800)) {
            return SEVEN_DAY;
        }
        if ( seconds.equals(2592000)) {
            return THIRTY_DAY;
        }
        if ( seconds.equals(5184000)) {
            return SIXTY_DAY;
        }
        if ( seconds.equals(7776000)) {
            return NINETY_DAY;
        }
        throw new UnsupportedOperationException(
                "The seconds " + seconds + " is not supported!"
        );
    }
}
